<?php
namespace app\m\controller;

use app\common\controller\FrontController;
use app\common\logic\MemberLogic;
use app\common\logic\SmsLogic;
use think\captcha\Captcha;
use think\facade\Request;
use think\facade\Session;

class Publics extends FrontController
{
    public function initialize()
    {
        $this->noCheckLoginController = true;
        parent::initialize();
    }
    public function index()
    {
        return $this->fetch();
    }

    public function test()
    {
        dump(strtotime('2018-07-03 18:17:00'));
        dump(date('Y-m-d H:i:s', 1530613292));
        dump(getWapMemberNickname(13011112222));
//        return $this->fetch();
    }

    public function get_vcode(){
        $phone = input('phone');
        $imgcode = input('imgcode');
        $captchaType = input('ct','loginBox');//验证码类型，用于区分多个验证码
        $captcha = new Captcha();
        if( !$captcha->check($imgcode,$captchaType)) {
            $this->error('图形验证码错误');
        }
        $smsLogic = new SmsLogic($this->getProjectId());
        $jieguo = $smsLogic->sendVcode($phone);
        if($jieguo['err_code'] != 0){
            $this->error($jieguo['msg']);
        }
        else{
            $this->success($jieguo['msg']);
        }
    }
    public function img_vcode(){
        $captchaType = input('ct','loginBox');//验证码类型，用于区分多个验证码
        $captcha = new Captcha();
        // 设置验证码字符为纯数字
        $captcha->codeSet = '123456789';
        $captcha->length   = 4;
        $captcha->fontSize = 40;
        return $captcha->entry($captchaType);
    }
    public function reg(){
        $params = input('post.');
        $params['mobile'] = $params['phone'];
        $memberLogic = new MemberLogic();
        $jieguo = $memberLogic->regMember($params);
        if ($jieguo['err_code'] !== 0) {
            $this->error($jieguo['msg']);
        }
        else{
            $this->success($jieguo['msg']);
        }
    }
    public function login(){
        $phone = input('phone');
        $pwd = input('pwd');

        $memberLogic = new MemberLogic();
        $jieguo = $memberLogic->loginByMobileAndPwd($phone, $pwd);
        if ($jieguo['err_code'] !== 0) {
            $this->error($jieguo['msg']);
        }
        else{
            $this->success($jieguo['msg']);
        }
    }
}
